package com.google.code.coma.gui;

import com.google.code.coma.domain.Computer;
import com.google.code.coma.domain.LifeCycleStep;
import com.google.code.coma.gui.util.ImageUtil;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.util.Callback;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public class ComputerCellRenderer implements Callback<ListView<Computer>, ListCell<Computer>> {
	@Override
	public ListCell<Computer> call(ListView<Computer> computerListView) {
		return new ComputerCell();
	}

	static class ComputerCell extends ListCell<Computer> {
		@Override
		public void updateItem(Computer item, boolean empty) {
			super.updateItem(item, empty);
			if (item != null) {
				BorderPane border = new BorderPane();
				if (item.getCurrent() == LifeCycleStep.FINISHED)
					border.setLeft(new ImageView(ImageUtil.getComputerOKImage()));
				else
					border.setLeft(new ImageView(ImageUtil.getComputerImage()));
				Label label = new Label("" + item.getCurrent());
				label.setAlignment(Pos.CENTER_LEFT);
				border.setCenter(label);
				setGraphic(border);
			}
		}
	}
}
